home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v9n21.arc / DGWRYTE.PAS < prev    next >
Pascal/Delphi Source File  |  1990-11-17  |  8KB  |  237 lines

  1. {
  2.  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3.  █                                                                         █
  4.  █        TITLE :      DGWRYTE.TPU                                         █
  5.  █      PURPOSE :      Replacement for WriteLn.                            █
  6.  █       AUTHOR :      David Gerrold, CompuServe ID:  70307,544            █
  7.  █  _____________________________________________________________________  █
  8.  █                                                                         █
  9.  █   Written in Turbo Pascal, Version 5.5,                                 █
  10.  █   with routines from TurboPower, Object Professional.                   █
  11.  █                                                                         █
  12.  █   Turbo Pascal is a product of Borland International.                   █
  13.  █   Object Professional is a product of TurboPower Software.              █
  14.  █  _____________________________________________________________________  █
  15.  █                                                                         █
  16.  █   This is not public domain software.                                   █
  17.  █   This software is copyright 1990, by David Gerrold.                    █
  18.  █   Permission is hereby granted for personal use.                        █
  19.  █                                                                         █
  20.  █        The Brass Cannon Corporation                                     █
  21.  █        9420 Reseda Blvd., #804                                          █
  22.  █        Northridge, CA  91324-2932.                                      █
  23.  █                                                                         █
  24.  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  25.                                                                             }
  26. { Compiler Directives ===================================================== }
  27.  
  28. {$A-}    {Switch word alignment off, necessary for cloning}
  29. {$R-}    {Range checking off}
  30. {$B-}    {Boolean complete evaluation off}
  31. {$S-}    {Stack checking off}
  32. {$I-}    {I/O checking off}
  33. {$N+,E+} {Simulate numeric coprocessor}
  34. {$M 16384,0,327680} {stack and heap}
  35. {$V-}    {Variable range checking off}
  36.  
  37. { Name ==================================================================== }
  38.  
  39. UNIT DgWryte;
  40.  
  41. { Interface =============================================================== }
  42.  
  43. INTERFACE
  44.  
  45. USES
  46. { Object Professional Units }
  47.   OpCrt;
  48.  
  49. { Functions and Procedures ================================================ }
  50.  
  51. FUNCTION Binary (B : byte) : string;
  52. { Returns string showing bits set in B. }
  53.  
  54. PROCEDURE BlankLine (Row, Attr : byte);
  55. { writes a blank line to screen }
  56.  
  57. PROCEDURE FastCenterAbs (S : string;  Row, Attr : byte);
  58. { shell for FastWrite, writes centered text }
  59.  
  60. PROCEDURE FastFlushAbs (S : string;  Row, Attr : byte);
  61. { shell for FastWrite, writes text flush right }
  62.  
  63. PROCEDURE FlushKbd;
  64. { Flushes the keyboard buffer, including mouse clicks. }
  65.  
  66. PROCEDURE RulerLine (Y : byte);
  67. { puts a ruler on line Y }
  68.  
  69. PROCEDURE Wryte (S : string);
  70. { shell for Write }
  71.  
  72. PROCEDURE WryteLn (S : string);
  73. { shell for WriteLn }
  74.  
  75. { ========================================================================= }
  76. { Implementation ========================================================== }
  77.  
  78. IMPLEMENTATION
  79.  
  80. { ========================================================================= }
  81. { Binary ================================================================== }
  82.  
  83. FUNCTION Binary (B : byte) : string;
  84. { Returns string showing bits set in B. }
  85.  
  86. VAR
  87.   Loop : byte;
  88.   Temp : string;
  89.   Ch   : char;
  90.  
  91. BEGIN
  92.   Temp := '';
  93.   Loop := 128;
  94.     repeat
  95.       if
  96.         B and Loop = Loop
  97.       then
  98.         Ch := '1'
  99.       else
  100.         Ch := '0';
  101.       Temp := Temp + Ch;
  102.       Loop := Loop div 2;
  103.     until
  104.       Loop <= 0;
  105.   Binary := Temp;
  106. END;
  107.  
  108. { BlankLine =============================================================== }
  109.  
  110. PROCEDURE BlankLine (Row, Attr : Byte);
  111. BEGIN
  112.   FastFill (ScreenWidth, ' ', Row, 1, Attr);
  113. END;
  114.  
  115. { FastFlushAbs  =========================================================== }
  116.  
  117. PROCEDURE FastCenterAbs (S : string;  Row, Attr : byte);
  118. { shell for FastWrite, writes centered text }
  119.  
  120. VAR
  121.   Len : byte absolute S;
  122.  
  123. BEGIN
  124.   FastWrite (S, Row, succ ((ScreenWidth - Len) div 2), Attr);
  125. END;
  126.  
  127. { FastFlushAbs  =========================================================== }
  128.  
  129. PROCEDURE FastFlushAbs (S : string;  Row, Attr : byte);
  130. { shell for FastWrite, writes text flush right }
  131. VAR
  132.   Len : byte absolute S;
  133.  
  134. BEGIN
  135.   FastWrite (S, Row, ScreenWidth - pred (Len), Attr);
  136. END;
  137.  
  138. { FlushKbd ================================================================ }
  139.  
  140. PROCEDURE FlushKbd;
  141. { Flushes the keyboard buffer, including mouse clicks. }
  142.  
  143. VAR
  144.   I : word;
  145. BEGIN
  146.   {$IFDEF UseMouse}
  147.   while KeyOrButtonPressed do
  148.     I := ReadKeyOrButton;
  149.   {$ELSE}
  150.   while KeyPressed do
  151.     I := ReadKeyWord;
  152.   {$ENDIF}
  153. END;
  154. {
  155.   Identical to FlushKeyboard in Object Professional's TPUI unit.
  156. }
  157.  
  158. { RulerLine =============================================================== }
  159.  
  160. PROCEDURE RulerLine (Y : byte);
  161. { puts a ruler on line Y }
  162.  
  163. VAR
  164.   Loop : byte;
  165.  
  166. BEGIN
  167.   For Loop := 0 to 7 do
  168.     FastWrite ('1234567890', Y, succ (Loop * 10), LightRed);
  169. END;
  170.  
  171. { Wryte =================================================================== }
  172.  
  173. PROCEDURE Wryte (S : string);
  174. {
  175.   The Turbo Pascal compiler generates extra code when it compiles a
  176.   call to WriteLn.  This is because WriteLn must parse both strings
  177.   and variables before it can write them.  Each call to the procedure
  178.   carries the baggage of the parsing routines.
  179.  
  180.   WryteLn is a shell procedure for WriteLn.
  181.  
  182.   By having only one call to WriteLn in an entire program and calling
  183.   it through a shell procedure, the program will trade some speed for
  184.   code size -- but if speed is really critical, you should be using
  185.   Object Professional's FastWrite procedures instead.
  186.  
  187.   Multiple variables can still be passed by concatenating them:
  188.   WryteLn ('The time is now: ' + TimeStr + '.');
  189. }
  190.  
  191. BEGIN
  192.   Write (S);
  193. END;
  194.  
  195. { WryteLn ================================================================= }
  196.  
  197. PROCEDURE WryteLn (S : string);
  198. {
  199.   The Turbo Pascal compiler generates extra code when it compiles a
  200.   call to WriteLn.  This is because WriteLn must parse both strings
  201.   and variables before it can write them.  Each call to the procedure
  202.   carries the baggage of the parsing routines.
  203.  
  204.   WryteLn is a shell procedure for WriteLn.
  205.  
  206.   By having only one call to WriteLn in an entire program and calling
  207.   it through a shell procedure, the program will trade some speed for
  208.   code size -- but if speed is really critical, you should be using
  209.   Object Professional's FastWrite procedures instead.
  210.  
  211.   Multiple variables can still be passed by concatenating them:
  212.   WryteLn ('The time is now: ' + TimeStr + '.');
  213. }
  214.  
  215. BEGIN
  216.   WriteLn (S);
  217. END;
  218.  
  219. { ========================================================================= }
  220. { Initialization ========================================================== }
  221.  
  222. { no initialization needed }
  223. END.
  224.  
  225. { ========================================================================= }
  226. { ========================================================================= }
  227.  
  228. VERSION HISTORY:
  229.   9005.05
  230.     Started with DgWryte, BlankLine, RulerLine, and FastFlushAbs.
  231.  
  232. { ========================================================================= }
  233.  
  234. NOTES:
  235.  
  236. { ========================================================================= }
  237.